﻿using System;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using QLTB.BusinessLayer;
using QLTB.BusinessObjects;
using QLTB.Common;

namespace QLTB.ThietBi.UI
{
    public partial class frmDetail : XtraForm
    {
        public frmDetail()
        {
            InitializeComponent();
            TBL_quyenBL.IgnoreError = true;
            if (!TBL_quyenBL.isXem(EnumComponent.iComponents))
            {
                tabLinhkien.Visible = false;
            }
            if (!TBL_quyenBL.isXem(EnumComponent.iEquipHistory))
            {
                tabLichsu.Visible = false;
            }
            TBL_quyenBL.IgnoreError = false;
        }

        public TBL_THIETBI ThietBi
        {
            set
            {
                ucLK.ThietBi = value;
                ucLS.ThietBi = value;
                if (value != null)
                {
                    Text = "Chi Tiết - " + value.TenTB;
                }
            }
        }

        private frmMain Controller
        {
            get { return (frmMain) ParentForm; }
        }


        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);
            if (Controller != null)
            {
                //Controller.iRefesh.ItemClick += new ItemClickEventHandler(iRefesh_ItemClick);
                // Controller.IAdd.ItemClick += new ItemClickEventHandler(IAdd_ItemClick);
            }
        }


        public void Set(InfoStyle style)
        {
            if (style == InfoStyle.LK)
            {
                TabControl.SelectedTabPage = tabLinhkien;
            }
            else
            {
                TabControl.SelectedTabPage = tabLichsu;
            }
        }

        private void IAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            //throw new NotImplementedException();
            if (Visible)
            {
            }
        }

        private void iRefesh_ItemClick(object sender, ItemClickEventArgs e)
        {
            //throw new NotImplementedException();
            if (Visible)
            {
                //MessageBox.Show("Hi hi");  
            }
        }

        private void frmLinhKien_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = !Program._exit;
        }


        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                    //case Keys.Alt | Keys.D:
                    //    //MessageBox.Show("You are stupid");
                    //    return true;

                    //// some more cases...  

                    //case Keys.F1:
                    //    //ucToolBar_HelpClick(ucBar);
                    //    F11Execute();
                    //    return true;
                    //case Keys.F3:
                    //    F3Execute();
                    //    return true;
                    //case Keys.F4:
                    //    F4Execute();
                    //    return true;
                    //case Keys.F5:
                    //    F5Execute();
                    //    return true;
                    //case Keys.F6:
                    //    F9Execute();
                    //    return true;
                    //case Keys.F7:
                    //    F7Execute();
                    //    return true;
                    //case Keys.F8:
                    //    F8Execute();
                    //    return true;
                    //case Keys.F9:
                    //    F9Execute();
                    //    return true;
                    //case Keys.F11:
                    //    F11Execute();
                    //    return true;
                    //case Keys.F12:
                    //    F12Execute();
                    //    return true;

                case Keys.Escape:
                    Close();
                    EscapeExecute();
                    return true;

                case Keys.Alt | Keys.X:
                    Close();
                    return true;

                case Keys.F10:
                    F10Execute();
                    Close();
                    return true;
            }

            return false;
        }

        private void F10Execute()
        {
        }

        private void EscapeExecute()
        {
        }
    }

    public enum InfoStyle
    {
        LK,
        LS
    }
}